package br.com.igrejacristavida.activity;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import br.com.igrejacristavida.adapter.PregacaoAdapter;
import br.com.igrejacristavida.model.Pregacao;

public class PregacoesActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_pregacoes);

		getActionBar().setDisplayHomeAsUpEnabled(true);

		final ListView listview = (ListView) findViewById(R.id.pregacoesList);
		List<Pregacao> pregacoes = getPregacoes();

		final PregacaoAdapter adapter = new PregacaoAdapter(this,  pregacoes);
		listview.setAdapter(adapter);

		listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> parent, final View view, int position, long id) {
				Pregacao pregacao = adapter.getItem(position);
				
				Intent intent = new Intent(PregacoesActivity.this, PregacaoPlayerActivity.class);
				intent.putExtra("pregacao", pregacao);
				
				startActivity(intent);
			}
		});
	}

	private List<Pregacao> getPregacoes() {
		List<Pregacao> pregacoes = new ArrayList<Pregacao>();
		pregacoes.add(new Pregacao("Pregação 1", "Pr Domingos", "http://traffic.libsyn.com/domingosalves/Q_-_02_-_2_-_13-02-2014.mp3", null));
		pregacoes.add(new Pregacao("Pregação 2", "Pr Domingos", "http://traffic.libsyn.com/domingosalves/Q_-_02_-_2_-_13-02-2014.mp3", null));
		pregacoes.add(new Pregacao("Pregação 3", "Pr Domingos", "http://traffic.libsyn.com/domingosalves/Q_-_02_-_2_-_13-02-2014.mp3", null));
		return pregacoes;
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.pregacoes, menu);
		return true;
	}

	public boolean onOptionsItemSelected(MenuItem item) {
		Intent myIntent = new Intent(getApplicationContext(), MainActivity.class);
		startActivityForResult(myIntent, 0);
		return true;
	}
}
